<template>
  <div>
    <el-select
      v-model="selectedValue"
      :placeholder="placeholder"
      :disabled="disabled"
      :clearable="clearable"
      filterable
      @change="handleChange"
    >
      <el-option
        v-for="item in activityOptions"
        :key="item.activityId"
        :label="item.title"
        :value="item.activityId"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { listActivityOptions } from "@/api/secondclass/activity";

export default {
  name: "ActivitySelect",
  props: {
    value: {
      type: [Number, String],
      default: null
    },
    placeholder: {
      type: String,
      default: "请选择活动"
    },
    disabled: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      activityOptions: [],
      selectedValue: this.value
    };
  },
  watch: {
    value(val) {
      this.selectedValue = val;
    }
  },
  created() {
    this.loadActivityOptions();
  },
  methods: {
    loadActivityOptions() {
      listActivityOptions().then(response => {
        this.activityOptions = response.data;
      });
    },
    handleChange(value) {
      this.$emit("input", value);
      this.$emit("change", value);
    }
  }
};
</script> 